package com.zuikaku.nettydemo.utils;

public class ZuikakuTools {
    /**
     * byte数组转换为int
     * @param data
     * @return
     */
    public static int bytesToInt(byte[] data) {
        int num = 0;
        for (int i = 0; i <4; i++) {
            num <<= 8;
            num |= (data[i] & 0xff);
        }
        return num;
    }

    /**
     * int转换成byte数组
     * @param num
     * @return
     */
    public static byte[] intToBytes(int num) {
        byte[] b = new byte[4];
        for (int i = 0; i < 4; i++) {
            b[i] = (byte) (num >>> (24 - i * 8));
        }
        return b;
    }
}
